<template>
	<view class="simple-modal" :class="{ 'show': visible }" @touchmove.stop.prevent="">
		<view class="modal-mask" @click="close"></view>
		<view class="modal-content">
			<view class="modal-header">
				<text class="modal-title">{{ title }}</text>
				<text class="modal-close iconfont icon-guanbi" @click="close"></text>
			</view>
			<view class="modal-body">
				<slot></slot>
			</view>
			<view class="modal-footer" v-if="showFooter">
				<slot name="footer"></slot>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			title: {
				type: String,
				default: '提示',
			},
			showFooter: {
				type: Boolean,
				default: false,
			},
		},
		data() {
			return {
				visible: false,
			};
		},
		methods: {
			open() {
				this.visible = true;
			},
			close() {
				this.visible = false;
				this.$emit('close');
			},
		},
	};
</script>

<style lang="scss" scoped>
	.simple-modal {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		z-index: 999;
		display: flex;
		align-items: center;
		justify-content: center;
		visibility: hidden;
		opacity: 0;
		transition: all 0.3s ease-in-out;

		&.show {
			visibility: visible;
			opacity: 1;
		}

		.modal-mask {
			position: absolute;
			top: 0;
			left: 0;
			right: 0;
			bottom: 0;
			background-color: rgba(0, 0, 0, 0.5);
		}

		.modal-content {
			background-color: #fff;
			border-radius: 16rpx;
			width: 80%;
			max-width: 600rpx;
			position: relative;
			z-index: 1000;
			display: flex;
			flex-direction: column;

			.modal-header {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 30rpx;
				border-bottom: 1rpx solid #eee;

				.modal-title {
					font-size: 36rpx;
					font-weight: bold;
					color: #333;
				}

				.modal-close {
					font-size: 36rpx;
					color: #999;
				}
			}

			.modal-body {
				padding: 30rpx;
				flex-grow: 1;
				overflow-y: auto;
			}

			.modal-footer {
				padding: 20rpx 30rpx;
				border-top: 1rpx solid #eee;
			}
		}
	}
</style>
